define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'qingdongams/customer/equipment/index',
                    add_url: 'qingdongams/customer/equipment/add',
                    edit_url: 'qingdongams/customer/equipment/edit',
                    del_url: 'qingdongams/customer/equipment/del',
                    multi_url: 'qingdongams/customer/equipment/multi',
                    table: 'equipment',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'equipment.id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'product.name', title: __('产品名称'),operate: false},
                        {field: 'number', title: __('设备编号'), operate: 'LIKE'},
                        {field: 'logo', title: __('二维码'), formatter: Table.api.formatter.image, events: Table.api.events.image,operate: false},
                        {field: 'binding_status', title: __('绑定客户产品状态'), formatter: Table.api.formatter.status, searchList: {1: __('未绑定'), 0: __('已绑定')}},
                        {field: 'createtime', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                    ]
                ],
                //启用普通表单搜索
                search      : false,
            });
            $(".btn-downloaderweima").on("click",function(){
                var temp=table.bootstrapTable('getSelections');
                var ids = temp.map(item => item.id);
                ids = ids.toString();
                if(!ids){
                    Layer.msg("请选择要下载的二维码");return false;
                }
                var url = 'qingdongams/equipment/export_ercode?ids='+ids;
                window.location.href=url;

            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});